﻿namespace SourceCodeRepository.Model.Validators.Test
{
    using Entitites;
    using Infra.Validation;
    using Xunit;

    public class CodeSnippetValidatorFacts
    {
        [Fact]
        public void Test_CodeSnippet_Validator_Check_All_Errors()
        {
            var codeSnippet = new CodeSnippet();
            var validator = new CodeSnippetValidator();
            ValidationResult result = ValidationFactory.Validate(validator, codeSnippet);
            Assert.Equal(3, result.NumberOfErrors);
        }

        [Fact]
        public void Test_CodeSnippet_Validator_With_CodeSnippet_With_Only_SnippetText()
        {
            var codeSnippet = new CodeSnippet {SnippetText = "Test"};
            var validator = new CodeSnippetValidator();
            ValidationResult result = ValidationFactory.Validate(validator, codeSnippet);
            Assert.Equal(2, result.NumberOfErrors);
        }

        [Fact]
        public void Test_CodeSnippet_Validator_With_CodeSnippet_With_SnippetText_And_Contributor()
        {
            var codeSnippet = new CodeSnippet { SnippetText = "Test", Contributor = new Contributor() };
            var validator = new CodeSnippetValidator();
            ValidationResult result = ValidationFactory.Validate(validator, codeSnippet);
            Assert.Equal(1, result.NumberOfErrors);
        }

        [Fact]
        public void Test_CodeSnippet_Validator_With_CodeSnippet_With_SnippetText_And_Contributor_And_Language()
        {
            var codeSnippet = new CodeSnippet { SnippetText = "Test", Contributor = new Contributor(), Language = new Language() };
            var validator = new CodeSnippetValidator();
            ValidationResult result = ValidationFactory.Validate(validator, codeSnippet);
            Assert.Equal(0, result.NumberOfErrors);
        }

        [Fact]
        public void Test_CodeSnippet_Validator_With_CodeSnippet_Null()
        {
            var validator = new CodeSnippetValidator();
            ValidationResult result = ValidationFactory.Validate(validator, null);
            Assert.Equal(1, result.NumberOfErrors);
        }
    }
}
